package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpSellerStoreProductInfringingKeywordsBo;
import com.erp.gather.domain.vo.ErpSellerStoreProductInfringingKeywordsVo;
import com.erp.gather.service.IErpSellerStoreProductInfringingKeywordsService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 商品侵权词
 *
 * @author erp
 * @date 2023-12-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/sellerStoreProductInfringingKeywords")
public class ErpSellerStoreProductInfringingKeywordsController extends BaseController {

    private final IErpSellerStoreProductInfringingKeywordsService iErpSellerStoreProductInfringingKeywordsService;

    /**
     * 查询
     */
    @GetMapping("/selectKeywordText")
    public R<Object> selectKeywordText() {
        List<String> keywordsList = iErpSellerStoreProductInfringingKeywordsService.selectKeywordText();
        return R.ok(keywordsList);
    }
    /**
     * 给times+1
     */
    @GetMapping("/addTimes")
    public R<Object> addTimes(@Param("id") Long id) {
        return iErpSellerStoreProductInfringingKeywordsService.addTimes(id);
    }
    /**
     * 获取最新的一条
     */
    @GetMapping("/selectLastUpdateTime")
    public R<Object> selectLastUpdateTime() {
        Date updateTime = iErpSellerStoreProductInfringingKeywordsService.selectLastUpdateTime();
        return R.ok(updateTime);
    }

    /**
     * 查询商品侵权词列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreProductInfringingKeywordsVo> list(ErpSellerStoreProductInfringingKeywordsBo bo, PageQuery pageQuery) {
        return iErpSellerStoreProductInfringingKeywordsService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取商品侵权词详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSellerStoreProductInfringingKeywordsVo> getInfo(@NotNull(message = "主键不能为空")
                                                                @PathVariable Long id) {
        return R.ok(iErpSellerStoreProductInfringingKeywordsService.queryById(id));
    }

    /**
     * 新增商品侵权词
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreProductInfringingKeywordsBo bo) {
        return toAjax(iErpSellerStoreProductInfringingKeywordsService.insertByBo(bo));
    }

    /**
     * 修改商品侵权词
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreProductInfringingKeywordsBo bo) {
        return toAjax(iErpSellerStoreProductInfringingKeywordsService.updateByBo(bo));
    }

    /**
     * 删除商品侵权词
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreProductInfringingKeywordsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 侵权词检测
     *
     * @param type
     * @param id
     * @return
     */
    @GetMapping("/keyWordsDetection")
    public R<Object> keyWordsDetection(Integer type, Long id) {
        return iErpSellerStoreProductInfringingKeywordsService.keyWordsDetection(type, id);
    }

    /**
     * 更新缓存
     *
     * @return
     */
    @GetMapping("/getKeyWordsNowMap")
    public Map<String, Object> getKeyWordsNowMap() {
        return iErpSellerStoreProductInfringingKeywordsService.getKeyWordsNowMap();
    }

    /**
     * 设置关键词
     */
    @GetMapping("/setKeyWordsStatus")
    public R<Object> setKeyWordsStatus(
            Long keywordsId,
            Integer type) {
        return iErpSellerStoreProductInfringingKeywordsService.setKeyWordsStatus(keywordsId, type);
    }

    /**
     * 将公共产品库中产品出具报告
     */
    @PostMapping("/collectProductKeyWordsDetection")
    public void collectProductKeyWordsDetection(HttpServletResponse response, Integer type,Long userId) {
        iErpSellerStoreProductInfringingKeywordsService.collectProductKeyWordsDetection(response, type,userId);
    }



}
